/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.blue.log;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Formatter;
import java.util.List;

/**
 *
 * @author kelvio
 */
public class Log {

    private List<Appender> appenders = new ArrayList<>();    
    private String debugTag;
    private String errorTag;
    private String fatalTag;
    private String infoTag;
    private String warnTag;

    public Log(Class<?> clazz, Appender ... appenders) {
        String className = clazz.getName();
        this.debugTag = "DEBUG - [" + className +"]";
        this.errorTag = "ERROR - [" + className +"]";
        this.fatalTag = "FATAL - [" + className +"]";
        this.infoTag = "INFO - [" + className +"]";
        this.warnTag = "WARN - [" + className +"]";
        if (appenders.length > 0) {
            this.appenders.addAll(Arrays.asList(appenders));
        } else {
            this.appenders.add(new ConsoleAppender());
        }
        
    }
    
    
    
    private String format(String msg, Object ... args) {
        
        return new Formatter().format(msg, args).toString();
    }
    
    /**
     *
     * @param object
     * @param params
     */
    public void debug(String msg, Object ... args) {
        String formatedMessage = this.format(this.debugTag + msg, args);        
        for (Appender appender : appenders) {
            appender.debug(formatedMessage);
        }
    }

    /**
     *
     * @param object
     * @param params
     */
    public void error(String msg, Object ... args) {
        String formatedMessage = this.format(this.errorTag + msg, args);        
        for (Appender appender : appenders) {
            appender.error(formatedMessage);
        }
    }

    /**
     *
     * @param object
     * @param params
     */
    public void fatal(String msg, Object ... args) {
        String formatedMessage = this.format(this.fatalTag + msg, args);        
        for (Appender appender : appenders) {
            appender.fatal(formatedMessage);
        }
    }

    /**
     *
     * @param object
     * @param params
     */
    public void info(String msg, Object ... args) {
        String formatedMessage = this.format(this.infoTag + msg, args);        
        for (Appender appender : appenders) {
            appender.info(formatedMessage);
        }
    }

    /**
     *
     * @param object
     * @param params
     */
    public void warn(String msg, Object ... args) {
        String formatedMessage = this.format(this.warnTag + msg, args);        
        for (Appender appender : appenders) {
            appender.warn(formatedMessage);
        }
    }
 
}
